<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者，助力中小企业发展
// +----------------------------------------------------------------------
// | Copyright (c) 2017～2024  www.wdadmin.cn    All rights reserved.
// +----------------------------------------------------------------------
// | Wdadmin系统产品软件并不是自由软件，不加密，并不代表开源，未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn>   www.wdadmin.cn
// +----------------------------------------------------------------------
/**
 * Class DistributionMap
 * Desc  师傅分布图控制器
 * Create on 2024/11/8 11:12
 * Create by wangyafang
 */

namespace app\admin\controller\wddj;


use app\admin\model\wddj\Driver;
use app\admin\model\wddj\operation\City;
use app\admin\model\wddj\user\Area;
use app\common\controller\Backend;

class DistributionMap extends Backend
{
    public function _initialize()
    {
        parent::_initialize();
    }

    /**
     * Desc 查看
     * Create on 2024/10/26 17:23
     * Create by wangyafang
     */
    public function index()
    {

        $order = 'weigh desc,id desc';

        $cityList = (new City())
            ->where('status','normal')
            ->field("id,city")
            ->order($order)
            ->select();
        $areaModel = new Area();
        foreach ($cityList as &$v) {
            $cityArray = explode('/',$v['city']);
            $v->area = $areaModel->where('name',$cityArray[count($cityArray)-1])->field("REPLACE(REPLACE(mergename, '中国,', ''), ',', '/') AS shortname, lng, lat")->find();
        }
        if (!empty($cityList)) {
            $cityArray = explode('/',$cityList[0]['city']);
            $areaObj = $areaModel->where('name',$cityArray[count($cityArray)-1])->field("REPLACE(REPLACE(mergename, '中国,', ''), ',', '/') AS shortname, lng, lat")->find();
            $defaultTMapLatLng = $areaObj['lat'].','.$areaObj['lng'];
            $region = $areaObj['shortname'];
        } else {
            $defaultTMapLatLng = '40.0402718, 116.2735831';
            $region = '北京/北京市';
        }

        $driverList = (new Driver())->all();

        $geometries = [];
        foreach ($driverList as $vv) {
            $geometries[] = array(
                "id"=>$vv['id'],
                "driver_lat"=>$vv['driver_lat'],
                "driver_lng"=>$vv['driver_lng'],
                "properties"=> array(
                    "name"=> $vv->base_info['name'], // 名字字段
                    "acceptance_number"=> $vv->base_info['acceptance_number'],
                    "total_pay_amount"=> $vv->base_info['total_pay_amount'],
                ),
            );
        }
        $json_geometries_array = json_encode($geometries,JSON_UNESCAPED_UNICODE);
        $tencent_map_web_service_key = (new \app\api\model\wddj\Config())->where('id',1)->value('tencent_map_web_service_key');
        $markerDefault = $this->request->domain().'/assets/addons/wddj/img/driver.png';
        $this->assign('cityList',$cityList);
        $this->assign('defaultTMapLatLng',$defaultTMapLatLng);
        $this->assign('region',$region);
        $this->assign('json_geometries_array',$json_geometries_array);
        $this->assign('tencent_map_web_service_key',$tencent_map_web_service_key);
        $this->assign('markerDefault',$markerDefault);
        return $this->view->fetch();
    }
}



 